import 'package:url_launcher/url_launcher.dart';

/// Opens the provided [url] with the system default web browser.
Future<void> openUrl(String url) async {
  final uri = Uri.parse(url);
  if (!await launchUrl(uri)) {
    throw '无法打开 $url';
  }
}

/// Opens the dialer with the given [phoneNumber].
Future<void> makePhoneCall(String phoneNumber) async {
  final uri = Uri(scheme: 'tel', path: phoneNumber);
  if (!await launchUrl(uri)) {
    throw '无法拨打号码 $phoneNumber';
  }
}

/// Opens the SMS editor with the given [phoneNumber].
Future<void> sendSms(String phoneNumber) async {
  final uri = Uri(scheme: 'sms', path: phoneNumber);
  if (!await launchUrl(uri)) {
    throw '无法发送短信至 $phoneNumber';
  }
}
